// pages/auth/index.js
import { request } from "../../request/index.js";
import { login, showModal } from "../../utils/wx.js";
Page({

  /**
   * 页面的初始数据
   * cloudID: "34_eRAshof7IdqldRsvRiOrzay5MEEhZUofGioEDf91TEXrc1zXK_m2Ql0oBMY"
encryptedData: "6YkZ5ideXPMVAlI8pQc7B6eq5z1msbzjcNdMib/cN/rFbHnV3uby36GHhXLrX2/773MNPRV2klltr6oy11AuSxPzYqkwrttAHNguQOBEgKdTCIorqG6rly4IlYUkq/8MI7diQG2JS03DEv++JhS6FzTM10sUl9Jq87/p8Qc04Y7Z+2x9nBTRPyRs8vC/0AMA7IrOaGOWRKpYhayqT30jgWcyeNgdVj7oyVWdZJatmwBTOVOQp/STyGiAvro9AM9N62Ibo/gf7MlTS8hr6zCzIyIFHxdUGHLPD12VzUPsoWRf+ljv5zOJv7e4ggG2XM/gAppwnxRDmHWae2eJjhmoTtC2HAjsO5592SrFYwIe0O6pjOJ1xQLnZB9PWnyyRpNj2aqopcRKWYuRuq20U6APh8WqPcAPciZffxUnDBqWN017dpweUbVH8GFU800ZxmoJG0qoj/sFMrE7NxfB1LgHpdbTzIOih0sANLPgMagGo+OwhG9T+i0nfTs7RclMlklm"
errMsg: "getUserInfo:ok"
iv: "NrZWe8ersnw3KmqKtYBFpA=="
rawData: "{"nickName":"哈不拉多斯凯尼克","gender":1,"language":"zh_CN","city":"Guangzhou","province":"Guangdong","country":"China","avatarUrl":"https://wx.qlogo.cn/mmopen/vi_32/wlG1fkumgBqaht4lxSWLW7bV98jLM4Qic0EI5SYMTe08IZDiaxmkjYsLeJQWr5lV2njlib6RtBazRE45Fj8CX3jmw/132"}"
signature:
   */
  data: {

  },

  handelGetUserInfo(e){
    console.log(e);
    //获取用户信息：
    const { encryptedData, signature, iv, rawData } = e.detail;
    //获取code：
    login()
    .then(res => {
      const code = res.code;
      console.log(code);
      const loginParams = {encryptedData, signature, iv, rawData, code};
      return request({url: '/users/wxlogin', data: loginParams, method: 'post'})
      
    })
    .then(res => {
      // console.log(res);
      // const {token} = res;
      // wx.setStorageSync("token", token);
      showModal({content: '个人账号开发暂时无法获取支付相关权限/数据'})
      .then(res => {
        wx.navigateBack({
          delta: 1
        });
      });
    });

  }

})